<cpanel include="../../../config.php">

<?

/***************************************************************************
 *                                 manager.php
 *                            -------------------
 *   Begin                : Thursday, April 16, 2005
 *   Copyright            : (C) 2005 Point and Code
 *   Domain               : http://www.pointandcode.com/
 *   Email                : support@pointandcode.com
 *   Version              : 1.0.0
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$html_root_path = '../../../';
$page_title = "File Manager";
include $root_path.'common.php';
include $root_path.'page_header.php';









$template->set_filenames(array(
	'body' => $root_path.$template_path.'files/manager/manager.tpl')
);




$file_list = <<<EOF
<cpanel Fileman="listfiles($FORM{'dir'})">
EOF;



$actions_list = <<<EOF
<cpanel Fileman="showactions($FORM{'dir'},$FORM{'file'})">
EOF;

$folder_actions_list = <<<EOF
<cpanel Fileman="showdiractions($FORM{'dir'},$FORM{'file'})">
EOF;

$current_directory = $_GET['dir'];



//
// Let's parse the file list first. 
// Getting out the path to here...
//
$file_list = substr($file_list, 26);

$temp = explode('</td><td>', $file_list);
$path_row = $temp[1];

$temp = explode('</a> <a href="', $path_row);
$path_to_root = $temp[0];
$path_row = '<a href="'.$temp[1];

$path_items = explode('</a> /', $path_row);

$path_items_array = array();
$path_urls_array = array();

//
// Gets the root level path, which is different.
//
$temp = explode('<a href="', $path_to_root);
$path_to_root = $temp[1];
$temp = explode('dofileop.html?dir=', $path_to_root);
$path_to_root = $temp[1];
$temp = explode('"', $path_to_root);
$path_to_root = $temp[0];

array_push($path_urls_array, array('name' => '[root]', 'url'=>'/'));


//
// Does the rest of 'em
//
for($i=0;$i<(count($path_items)-1);$i++) {


	$temp = explode('>', $path_items[$i]);
	$temp_name = $temp[1];
	
	$temp=ltrim($temp[0]);
	$temp=substr($temp, 9);
	$temp=explode('"', $temp);
	$temp=explode('?dir=', $temp[0]);
	array_push($path_urls_array, array('name' => $temp_name, 'url' => $temp[1]));

}

//
// Assign variables for the breadcrumb navigation (path items)
//
foreach($path_urls_array as $row) {

	$template->assign_block_vars('breadcrumbrow', array(
		'NAME' => $row['name'],
		'URL' => $row['url'],
		'U_OPEN' => 'manager.php?dir='.$row['url'],
		)
	);

}







//
// The Selected Item
// Up here so we can hilight the selected row in the table.
// 

if (strpos($actions_list, 'File Type:  directory') > 0 ) {

	$template->assign_block_vars('switch_folder_selected', array());
	$template->assign_block_vars('switch_something_selected', array());
	$folder_selected = true;
	
	
} else if (!(strpos($actions_list, "File Type: can't stat") > 0) ) {

	$template->assign_block_vars('switch_file_selected', array());
	$template->assign_block_vars('switch_something_selected', array());
	
	
} 


$temp = explode('<b><font size=+1>', $actions_list);
$temp2 = explode('</font>', $temp[1]);

$selected_file_name = $temp2[0];

// File type:

$temp = explode('File Type:  ', $actions_list);
$temp2 = explode("\n", $temp[1]);

$selected_file_type = $temp2[0];

$temp = explode('File Url: <a href="', $actions_list);
$temp2 = explode('" target=_blank><b>', $temp[1]);

$selected_file_url = $temp2[0];

if (strpos($actions_list, '<a href="htmledit.html')>0) {
	$template->assign_block_vars('switch_html_file_selected', array());
}




//
// Right - next section!
// Let's grab the files themselves.
//

if (strpos($file_list, 'Up one level') > 0) {
	$temp = explode('Up one level</b></a></td><td></td><td></td></tr>', $file_list);
	$file_list = $temp[1];
} else {
	$temp = explode('Upload file(s)</b></a></td><td></td><td></td></tr>', $file_list);
	$file_list = $temp[1];

}



$temp = explode('<tr><td><a target=infofr href="createfile.html', $file_list);
$folder_list = $temp[0];

$just_files = '<tr><td><a target=infofr href="createfile.html'.$temp[1];

$folder_list_unclean = explode('</td></tr>', $folder_list);

$folder_list_array = array();
$i=0;

foreach($folder_list_unclean as $row) {


	// cuts off the tr tags
	$row=substr($row,18);
	$temp = explode('"',$row);
	$view_url = $temp[0];
	$select_url = $temp[4];
	
	// let's find the image url
	
	$temp = explode('<img src="', $row);
	$temp2 = explode('" border=0', $temp[1]);
	$image_url = $temp2[0];
	
	// moving on...
	
	$temp=explode('target=infofr>', $row);
	$temp2 = $temp[1];
	$temp3 = explode('</a>', $temp2);
	$name = $temp3[0];
	
	$temp = explode('</a></td><td></td><td>', $row);
	$permissions = $temp[1];
	
	$temp=explode('?dir=', $view_url);
	$path=$temp[1];
	
	//
	// Let's check if the name is the same as the selected file
	//
	
	if ($name == $selected_file_name) {
		$class = 'selected';
	} else {
		$class = '';
	}
	
	
	$folder_list_array[$i] = array(
		'view_url' => $view_url,
		'select_url' => $select_url,
		'name' => $name,
		'permissions' => $permissions,
		'path' => $path,
		'image_url' => $image_url,
		'class' => $class
	);
	$i++;
}


//
// Check for webprotect, and if present show the link...
//
$is_webprotect_available = <<<EOFpacman
<cpanelfeature webprotect>test</cpanelfeature>
EOFpacman;

$is_pro = <<<EOFpacman
<cpanelif $CPFLAGS{'pro'}>test</cpanelif>
EOFpacman;

$pro_leech_protect = <<<EOF
<cpanelfeature cpanelpro_leechprotect>test</cpanelfeature>
EOF;

if ($is_webprotect_available) {
	$template->assign_block_vars('switch_folder_selected.switch_webprotect', array());
};
if (!empty($pro_leech_protect) && $is_pro && $folder_selected == true) {
	$template->assign_block_vars('switch_folder_selected.switch_leech_protect', array());
};


//
// Assign variables for the folders
//
$k = 0;
foreach($folder_list_array as $row) {

	if (!empty($row['name'])) {

		$template->assign_block_vars('foldersrow', array(
			'ROWCLASS' => ($k%2) ? $template_cfg['class_row_1'] : $template_cfg['class_row_2'],
			'NAME' => $row['name'],
			'PATH' => $row['path'],
			'PERMISSIONS' => $row['permissions'],
			'CLASS' => $row['class'],
			'U_OPEN' => 'manager.php?dir='.$row['path'],
			'U_INFO' => 'manager.php?dir='.$current_directory.'&file='.$row['name'],
			'I_ICON' => '<img src="'.$html_root_path.$template_path.'files/manager/'.$row['image_url'].'">',

			
			)
		);
		
	$k++;
	}
}



//
// OK, the files now
//

$files_list_unclean = explode('</tr>', $just_files);


$files_list_array = array();
$i=0;

foreach($files_list_unclean as $row) {



	if (strpos($row, 'Create New File') === false) {

		$temp = explode('"', $row);
		$select_url = $temp[1];
		$image_url = $temp[3];
		
		$temp2 = $temp[6];
		$temp3 = explode('infofr>', $temp2);
		$temp4 = $temp3[1];
		$temp5 = explode('</a>', $temp4);
		$name = $temp5[0];
		
		$temp = explode('</td><td>', $temp4);
		$size = $temp[1];
		
		$temp2 = explode('</td>', $temp[2]);
		$permissions = $temp2[0];
		
		$temp = explode('select.html?dir=', $select_url);
		$temp2 = $temp[1];
		$temp3 = explode('&file=', $temp2);
		$path=$temp3[0];
		
		
		//
		// Let's check if the name is the same as the selected file
		//
		
		if ($name == $selected_file_name) {
			$class = 'selected';
		} else {
			$class = '';
		}
		
		$files_list_array[$i] = array(
			'image_url' => $image_url,
			'select_url' => $select_url,
			'name' => $name,
			'permissions' => $permissions,
			'path' => $path,
			'size' => $size,
			'class' => $class,
		);
		$i++;		
		
	}

}

//print_r($files_list_array);



//
// Assign variables for the files
//
foreach($files_list_array as $row) {

	if (!empty($row['name'])) {

		$template->assign_block_vars('filesrow', array(
			'ROWCLASS' => ($k%2) ? $template_cfg['class_row_1'] : $template_cfg['class_row_2'],
			'NAME' => $row['name'],
			'PATH' => $row['path'],
			'PERMISSIONS' => $row['permissions'],
			'SIZE' => $row['size'],
			'CLASS' => $row['class'],
			'U_INFO' => 'manager.php?dir='.$current_directory.'&file='.$row['name'],
			'I_ICON' => '<img src="'.$html_root_path.$template_path.'files/manager/'.$row['image_url'].'">'
			)
		);
	$k++;
	}
}







//
// Common interface elements
//

$upload_url = 'upload.php?dir='.$current_directory;
$new_folder_url = 'folder_new.php?dir='.$current_directory;
$new_file_url = 'file_new.php?dir='.$current_directory;







//
// Variables
//

$template->assign_vars(array(
	'ACTIONS' => $actions_list,
	'FOLDER_ACTIONS' => $folder_actions_list,
	
	'SELECTED_NAME' => $selected_file_name,
	'SELECTED_TYPE' => $selected_file_type,
	'SELECTED_URL' => $selected_file_url,
	
	'U_UPLOAD' => $upload_url,
	'U_NEW_FOLDER' => $new_folder_url,
	'U_NEW_FILE' => $new_file_url,
	
	'U_SELECTED_SHOW' => 'file_show.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_DELETE' => 'file_delete.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_RENAME' => 'file_rename.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_EDIT' => 'file_edit.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_COPY' => 'file_copy.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_MOVE' => 'file_move.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_PERMISSIONS' => 'file_permissions.php?dir='.$current_directory.'&file='.$selected_file_name,
	'U_SELECTED_HTML_EDIT' => 'file_html_edit.php?dir='.$current_directory.'&file='.$selected_file_name,

	'U_SELECTED_PASSWORD_PROTECT' => 'password_protect.php?dir='.$current_directory.'/'.$selected_file_name,
	'U_SELECTED_LEECH_PROTECT' => 'leech_protect.php?dir='.$current_directory.'/'.$selected_file_name,

	
	
	'L_DESCRIPTION' => $lang['file_manager_description'],
	'L_NEW_FOLDER' => $lang['new_folder'],
	'L_NEW_FILE' => $lang['new_file'],
	'L_UPLOAD_FILES' => $lang['upload_files'],

	'L_NAME' => $lang['name'],
	'L_SIZE' => $lang['size'],
	'L_PERMISSIONS' => $lang['permissions'],
	'L_ACTION' => $lang['action'],
	'L_GET_INFO' => $lang['get_info'],
	
	)
);




//
// Woohoo! All done!
//
$template->pparse('body');




include $root_path.'page_tail.php';




?>